package com.rainbow.support.half.message.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * rocketMq半事务
 * 通用处理初始化类
 * @author 傅为地
 */
@Configuration
@AutoConfigureAfter(value = {DataSourceAutoConfiguration.class})
@ConditionalOnBean(DataSource.class)
public class HalfMsgAutoConfig {

    /**
     * 实例化日志工具
     * @return jdbcTemplate
     */
    @Bean(name="jdbcTemplate")
    @Order(Ordered.HIGHEST_PRECEDENCE)
    @ConditionalOnMissingBean(JdbcTemplate.class)
    public JdbcTemplate jdbcTemplate(@Qualifier("dataSource") DataSource dataSource){
        return new JdbcTemplate(dataSource);
    }
}
